﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using BookingHotel.ManagerHotel;

namespace BookingHotel
{
    class MainProgram
    {
        static void Main(string[] args)
        {
            HotelManager _hotelManager = new HotelManager();
            if (args.Length != 0)
            {
                Console.WriteLine(args[0]);
                try
                {
                    StreamReader inputSream = File.OpenText(args[0]);
                    Console.SetIn(inputSream);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine("Lo standard Input rimane quello di default.");
                }
                
            }

            do
            {
                String currentLine = Console.ReadLine();
                if (currentLine == null)
                {
                    break;
                }
                VerbosePrinting.VerbosePrint("Command --> " + currentLine);
                String[] currentCommand = currentLine.Split(' ');
                switch (currentCommand[0])
                {
                    case "sleep":
                        Console.WriteLine("sleep {0}", currentCommand[1]);
                        System.Threading.Thread.Sleep(int.Parse(currentCommand[1]) * 1000);
                        break;
                    case "set":
                        switch (currentCommand[1])
                        {
                            case "hotel":
                                _hotelManager.SetHotelName(currentCommand[2]);
                                break;
                            case "room":
                                _hotelManager.AddRoom(currentCommand[2], int.Parse(currentCommand[3]), decimal.Parse(currentCommand[4]), int.Parse(currentCommand[5]));
                                break;
                            case "period":
                                _hotelManager.AddPeriod(Convert.ToDateTime(currentCommand[2]), Convert.ToDateTime(currentCommand[2]), decimal.Parse(currentCommand[4]));
                                break;
                            case "locality":
                                _hotelManager.SetHotelLocality(currentCommand[2]);
                                break;
                            default:
                                break;
                        }
                        break;
                    case "get":
                        switch (currentCommand[1])
                        {
                            case "room":
                                _hotelManager.GetFreeRoomOfThisType(currentCommand[2], Convert.ToDateTime(currentCommand[3]), Convert.ToDateTime(currentCommand[4]));
                                break;
                            case "locality":
                                Console.WriteLine(_hotelManager.GetLocality(currentCommand[2]));
                                break;
                            case "client":
                                Console.WriteLine(_hotelManager.GetDataClient(int.Parse(currentCommand[1])));
                                break;
                            case "periods":
                                _hotelManager.PrintInConsolleAllPeriods();
                                break;
                            default:
                                break;
                        }
                        break;
                    case "create":
                        switch (currentCommand[1])
                        {
                            case "booking":
                                //inizio prenotazione, fine prenotazione, numero persone, tipo stanza
                                _hotelManager.FindRoom(Convert.ToDateTime(currentCommand[2]), Convert.ToDateTime(currentCommand[3]), Convert.ToInt32(currentCommand[4]), currentCommand[5]);
                                break;
                            default:
                                break;
                        }
                        break;
                    default:
                        break;
                }

            } while (true);

        }
    }
}
